package com.thread.www;

/**
 * Created by 27340 on 2017/11/20.
 */
public class NotifyDEmo {
    public static class Thread1 implements Runnable{

        @Override
        public void run() {
            System.out.println("this is t1");
            while (true){
                synchronized (this){
                    try {
                        System.out.println("t1 wait");
                        wait();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }

        }
    }

    public class Thread2 implements Runnable{

        @Override
        public void run() {

        }
    }

    public static void main(String[] args) {

        Thread1 n = new Thread1();
        Thread t1 = new Thread(n);
        t1.start();
        while (true){
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println("主线程  is run");
            synchronized (n){
                n.notifyAll();
            }
        }
    }
}
